package com.zide.member.mapper.community;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.zide.auth.domain.entity.member.MemberUser;
import com.zide.common.config.mybatisplus.ZiDeMapperPlus;
import com.zide.common.core.domain.PageResult;
import com.zide.member.entity.knowledge.CommunityEssay;
import com.zide.member.vo.result.community.CommEssayResultVO;
import com.zide.member.vo.search.community.CommEssaySearchVO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 养宠资讯 数据层
 *
 * @author 石添添
 */
@Mapper
public interface CommunityEssayMapper extends ZiDeMapperPlus<CommunityEssay> {

    default PageResult<CommEssayResultVO> selectPage(CommEssaySearchVO searchVO) {
        MPJLambdaWrapper<CommunityEssay> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(CommunityEssay.class)
                .selectAs(MemberUser::getNickname, CommEssayResultVO::getNickname)
                .selectAs(MemberUser::getAvatar, CommEssayResultVO::getAvatar)
                .leftJoin(MemberUser.class, MemberUser::getId, CommunityEssay::getMemberId)
                .orderByAsc(CommunityEssay::getCreateTime);
        return selectJoinPage(searchVO,CommEssayResultVO.class, wrapper);
    }
}
